//
//  HWGameClassifyLeftCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/3/3.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWGameClassifyLeftCell: UITableViewCell {
    var bgView:UIView!
    var titleLabel:UILabel!
    var leftView:UIView!
    var model:HWGameClassifyConfigModel? {
        didSet {
            titleLabel.text = model?.name
            if model?.isSelected == true {
                bgView.backgroundColor = .white
                titleLabel.font = .boldSystemFont(ofSize: 12*widthScale)
                titleLabel.textColor = .colorWithHexString(hexString: "#444444")
                leftView.isHidden = false
            }else {
                bgView.backgroundColor = .colorWithHexString(hexString: "#F7F7F7")
                titleLabel.font = .systemFont(ofSize: 12*widthScale)
                titleLabel.textColor = .colorWithHexString(hexString: "#888888")
                leftView.isHidden = true
            }
        }
    }
    class func cellWithTableView(tableView:UITableView) -> (HWGameClassifyLeftCell) {
        let reUse:String = "HWGameClassifyLeftCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWGameClassifyLeftCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWGameClassifyLeftCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = .white
        
        bgView = UIView()
        bgView.backgroundColor = .clear
        contentView.addSubview(bgView)
        
        titleLabel = HWLabel.createLabel(title: "", color: "#888888", font: 12*widthScale)
        bgView.addSubview(titleLabel)
        
        leftView = UIView()
        leftView.frame = CGRect(x: 0, y: 0, width: 4*widthScale, height: 13*widthScale)
        UIColor.gradientColor(view: leftView, colors: [UIColor.colorWithHexString(hexString: "#FFB60A").cgColor,UIColor.colorWithHexString(hexString: "#F66A05").cgColor], start: CGPoint(x: 0, y: 0), end: CGPoint(x: 0, y: 1))
        bgView.addSubview(leftView)
    }
    
    func initFrame() -> Void {
        bgView.snp.makeConstraints { make in
            make.bottom.equalTo(-2*widthScale)
            make.top.left.right.equalToSuperview()
        }
        
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(16*widthScale)
            make.bottom.equalTo(-16*widthScale)
            make.center.equalToSuperview()
        }
        
        leftView.snp.makeConstraints { make in
            make.left.centerY.equalToSuperview()
            make.height.equalTo(13*widthScale)
            make.width.equalTo(4*widthScale)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
